Skip to content

fix(project): reject empty/whitespace-only --name in create and update#36

Open
lxcario wants to merge 1 commit into
TestSprite:mainfrom
lxcario:fix/project-name-whitespace
Open

fix(project): reject empty/whitespace-only --name in create and update#36
lxcario wants to merge 1 commit into
TestSprite:mainfrom
lxcario:fix/project-name-whitespace

Conversation

@lxcario

@lxcario lxcario commented Jun 25, 2026

Copy link
Copy Markdown

What

testsprite project create and project update accept a whitespace-only --name (e.g. --name " ") and send it to the backend verbatim, creating a blank-named project.

Why this matters

A whitespace-only name produces a junk project record that's effectively unidentifiable in project list and the dashboard. The sibling test create already rejects this input, so the two write paths behave inconsistently for the same kind of value.

Reproduction

# project create — whitespace name is ACCEPTED (exit 0), would be sent as "   "
$ testsprite project create --type frontend --name "   " --url http://example.com --dry-run --output json
{
  "id": "p_dryrun_2026",
  "type": "frontend",
  "name": "   ",
  ...
}

# control: an EMPTY name is correctly rejected (exit 5)
$ testsprite project create --type frontend --name "" --url http://example.com --dry-run
Error: --name is required        # exit 5

# sibling `test create` — whitespace name is correctly rejected (exit 5)
$ testsprite test create --project proj_1 --type frontend --name "   " --code-file x.ts --dry-run --output json
{ "error": { "code": "VALIDATION_ERROR", "nextAction": "Flag `--name` is invalid: is required." } }   # exit 5

Root cause

src/commands/project.ts. The command action validates the name with if (!cmdOpts.name), which a whitespace-only string passes (a non-empty string is truthy), and runCreate / runUpdate only check the upper length bound:

if (opts.name !== undefined && opts.name.length > 200) {
  throw localValidationError('--name must be at most 200 characters');
}

There is no lower-bound / whitespace check, so " " flows straight into the request body.

Fix

Reject empty / whitespace-only names in both runCreate and runUpdate, before the existing length checks:

if (opts.name !== undefined && opts.name.trim().length === 0) {
  throw localValidationError('--name must not be empty or whitespace-only');
}

This mirrors the existing requireString whitespace guard in src/lib/validate.ts that test create already uses (added as "dogfood P1 fix #1" to stop junk records reaching the backend) — the project path just wasn't going through it.

Tests

Added 2 tests to src/commands/project.test.ts (one for runCreate, one for runUpdate) asserting a whitespace-only --name rejects with VALIDATION_ERROR / exit 5 and makes no network call. Both fail on main before this fix and pass after.

  • Before (main): Tests 16 failed | 1359 passed | 72 skipped
  • After (this branch): Tests 16 failed | 1361 passed | 72 skipped (+2 new tests)

The 16 failures are pre-existing and environment-specific (Windows path/line-ending), unrelated to this change — see #4.

Verification

  • npm test: same 16 pre-existing (environment-specific) failures as baseline, zero new
  • npm run typecheck: pass
  • npm run lint: pass

project create/update validated --name with the action handler's if (!name) check, which a whitespace-only string passes (a non-empty string is truthy). The blank name was then sent verbatim, creating a junk-named project. The sibling 	est create already rejects this via the requireString whitespace guard (dogfood P1 fix TestSprite#1); this aligns project create/update with that behavior. Adds 2 regression tests.
@zeshi-du

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@zeshi-du, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa344685-d7f7-45c5-a8c0-ab69514ad4a3

📥 Commits

Reviewing files that changed from the base of the PR and between 18f6e6e and e70c25c.

📒 Files selected for processing (2)
  • src/commands/project.test.ts
  • src/commands/project.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Video asset

2 participants